package com.ungao.framework.define;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Bean定义
 *
 * @author vic-ungao
 */
public class BeanDefinition {

    /**
     * 原始对象
     */
    private Object original;

    /**
     * 代理对象
     */
    private Object proxyBean;

    /**
     * 实现对象
     */
    private final Map<String, Object> singletonBeans;

    public BeanDefinition(Object original, Object proxyBean) {
        this();
        this.setOriginal(original);
        this.setProxyBean(proxyBean);
    }

    public BeanDefinition() {
        this.singletonBeans = new ConcurrentHashMap<>();
    }

    public Object getOriginal() {
        return original;
    }

    public BeanDefinition setOriginal(Object original) {
        this.original = original;
        return this;
    }

    public Object getProxyBean() {
        return proxyBean;
    }

    public BeanDefinition setProxyBean(Object proxyBean) {
        this.proxyBean = proxyBean;
        return this;
    }

    public boolean isInterface() {
        return this.singletonBeans.size() > 0 || original == null;
    }

    public Map<String, Object> getSingletonBeans() {
        return singletonBeans;
    }

    public Object get(String beanName) {
        return this.singletonBeans.get(beanName);
    }

    public BeanDefinition put(String beanName, Object proxyBean) {
        this.singletonBeans.putIfAbsent(beanName, proxyBean);
        return this;
    }
}
